* Set globals and run all files in CAP replication package
* 12/23/2025

clear all
set more off

* set working directory (only the following single line needs to be changed)
global main "[INSERT DIRECTORY HERE]"
global data "$main/data"

* generate folders (the user should already have downloaded the folders "code" and "data", and subfolder "raw" inside "data", with all of the raw datasets contained there)
cd $main
cap mkdir "output"
cap mkdir "data/intermediate"
cap mkdir "data/intermediate/cleaned_usda"
cap mkdir "data/temp"
cap mkdir "data/for_analysis"

* additional globals
global raw "$main/data/raw"
global intermediate "$main/data/intermediate"
global for_analysis "$main/data/for_analysis"
global temp "$main/data/temp"
global output "$main/output"

* run do files and R scripts in order
cd "$main/code"
do 01_read_ipums.do
do 02_restrict_sample.do
do summary_stats.do
shell RAW="$raw" INTERMEDIATE="$intermediate" FOR_ANALYSIS="$for_analysis" TEMP="$temp" OUTPUT="$output" ///
    /Library/Frameworks/R.framework/Resources/bin/R --vanilla < "policy_map.R"
do takeup_regressions.do
do placebo_tests.do
do robustness_balanced.do
do robustness_target_sample.do
shell RAW="$raw" INTERMEDIATE="$intermediate" FOR_ANALYSIS="$for_analysis" TEMP="$temp" OUTPUT="$output" ///
    /Library/Frameworks/R.framework/Resources/bin/R --vanilla < "read_usda_pdfs.R"
do admin_data_analysis.do
do targeting_analysis.do
do cap_format_regressions.do
do food_access_regressions.do
shell RAW="$raw" INTERMEDIATE="$intermediate" FOR_ANALYSIS="$for_analysis" TEMP="$temp" OUTPUT="$output" ///
    /Library/Frameworks/R.framework/Resources/bin/R --vanilla < "access_map.R"
do political_party.do
do pretrends.do
do jones_et_al_comparison.do
do calculate_cost.do
do subsample_models.do
